import { NextRequest, NextResponse } from 'next/server';

// Account Routes
export async function POST(request: NextRequest) {
    const body = await request.json();
    const { pathname } = request.nextUrl;
    if (pathname.endsWith('/registration')) {
        return NextResponse.json(await fetchBackend('/registration', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify(body),
        }));
    } else if (pathname.endsWith('/login')) {
        return NextResponse.json(await fetchBackend('/login', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify(body),
        }));
    } else { // /accounts/:accountId (PUT)
        const accountId = pathname.split('/').pop();
        return NextResponse.json(await fetchBackend(`/accounts/${accountId}`, {
            method: 'PUT',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify(body),
        }));
    }
}